<template>
  <zero-vxe-grid v-loading="loading">
    <div slot="header">
      <!--    查询条件-->
      <el-collapse-transition>
        <div v-show="viewModuleOptions.showSearch">
          <vxe-form ref="queryForm" :data="viewModuleOptions.searchForm" title-align="right">
            <vxe-form-item title="生成的文件" field="name" :item-render="{}">
              <template #default="{ data }">
                <vxe-input max-length="50" v-model="data.name" showWordCount clearable placeholder="请输入生成的文件"/>
              </template>
            </vxe-form-item>

            <vxe-form-item title="分组编码" field="groupCode" :item-render="{}">
              <template #default="{ data }">
                <vxe-input max-length="10" v-model="data.groupCode" showWordCount clearable
                           placeholder="请输入分组编码"/>
              </template>
            </vxe-form-item>
            <vxe-form-item title="创建时间" field="createTime" :item-render="{}">
              <template #default="{ data }">
                <el-date-picker v-model="data.createTime" style="width: 240px" value-format="yyyy-MM-dd"
                                type="daterange" range-separator="-" start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :picker-options="viewModuleOptions.pickerOptions" :editable="false"/>
              </template>
            </vxe-form-item>
            <vxe-form-item>
              <vxe-button content="搜索" round @click="searchSubmit" status="primary"/>
              <vxe-button content="重置" round @click="searchResetForm"/>
            </vxe-form-item>
          </vxe-form>
        </div>
      </el-collapse-transition>
    </div>
    <div slot="main">
      <!--表格-->
      <vxe-grid v-bind="viewModuleOptions" :ref="viewModuleOptions.ref" v-on="viewModuleOptions.fns">
        <template #buttons>
          <vxe-button content="批量删除" status="danger" icon="vxe-icon-delete" @click="handleDelete"
                      v-hasPermi="['tableInfo:delete']" :disabled="viewModuleOptions.dataListSelections.length <= 0"/>
<!--          <vxe-button content="批量代码生成" icon="vxe-icon-cloud-upload" v-hasPermi="['tableInfo:import']"-->
<!--                      @click="initDialog({ ref: genCodeRef,row:row })"/>-->
          <vxe-button content="导入生成信息" status="primary" icon="el-icon-upload"
                      @click="initDialog({ ref: importTableRef })"
                      v-hasPermi="['tableInfo:importGenInfo']"/>
        </template>

        <template #tools>
          <vxe-button :title="viewModuleOptions.showSearch ? '隐藏搜索' : '显示搜索'" @click="showOrHideClick"
                      icon="vxe-icon-search" circle/>
          <vxe-button :title="viewModuleOptions.isFullscreen ? '还原' : '全屏'" @click="toggleIsFullscreen"
                      class="tool-btn"
                      :icon="viewModuleOptions.isFullscreen ? 'vxe-icon-minimize' : 'vxe-icon-fullscreen'" circle/>
        </template>

        <template #operation="{ row }">
          <vxe-button mode="text" status="primary" content="修改" v-hasPermi="['tableInfo:updateTableInfo']"
                      @click="handleEditTable(row)"></vxe-button>
          <vxe-button mode="text" status="primary" content="代码生成" v-hasPermi="['tableInfo:genCode']"
                      @click="initDialog({ ref: genCodeRef,row:row })"></vxe-button>
          <vxe-button mode="text" status="danger" content="删除" v-hasPermi="['tableInfo:delete']"
                      @click="handleDelete(row)"></vxe-button>
        </template>
      </vxe-grid>

      <importTable :ref="importTableRef" :axios="viewModuleOptions.axios" :loading.sync="loading"
                   :addUrl="viewModuleOptions.addUrl" :byIdUrl="viewModuleOptions.byIdUrl" :getDataList="getDataList"
                   :updateUrl="viewModuleOptions.updateUrl"/>

      <genCode :ref="genCodeRef" :axios="viewModuleOptions.axios" :loading.sync="loading"
               :addUrl="viewModuleOptions.addUrl" :byIdUrl="viewModuleOptions.byIdUrl" :getDataList="getDataList"
               :updateUrl="viewModuleOptions.updateUrl"/>
    </div>
  </zero-vxe-grid>
</template>

<script>

import viewModule from '@/mixins/vxe-grid.js'; // 表格js
import {checkPermi} from "@/utils/permission.js"; //权限js
import genCode from './components/genCode.vue'; // 生成代码
import importTable from './components/importTable.vue'; // 导入、导出模块


export default {
  name: "tableInfo",
  mixins: [viewModule],
  components: {
    importTable,
    genCode
  },
  data() {
    return {
      addUpdateDialogRef: 'addUpdateDialogRef',
      importTableRef: 'importTableRef',
      genCodeRef: 'genCodeRef',
      viewModuleOptions: {
        axios: this.$axiosGen, // 请求的微服务，默认授权服务
        dataUrl: '/tableInfo/pageList',
        removeUrl: '/tableInfo',
        exportUrl: '/tableInfo/export',
        importUrl: '/tableInfo/import',
        importTemplateUrl: '/tableInfo/importTemplate',
        columns: [
          {type: 'checkbox', width: 60},
          {field: 'datasourceName', title: '数据源', showOverflow: true, resizable: true},
          {field: 'databaseName', title: '数据库', resizable: true},
          {field: 'tableName', title: '表名称', resizable: true},
          {field: 'tableComment', title: '表注释', showOverflow: true, resizable: true},
          {field: 'entityName', title: '实体', showOverflow: true, resizable: true},
          {field: 'createTime', title: '创建时间', sortable: true, width: '150px'},
          {field: 'updateTime', title: '修改时间', width: '150px'},
          {
            title: '操作', width: 150, slots: {default: 'operation'},
            visible: checkPermi(['tableInfo:update', 'tableInfo:delete'])
          }
        ]
      }
    };
  },
  watch: {
    //时间筛选特殊处理，重置createTime时也将根据这个字段衍生出来的字段置为null
    'viewModuleOptions.searchForm.createTime': function (val) {
      this.viewModuleOptions.searchForm.startCreateTime = val ? val[0] : null
      this.viewModuleOptions.searchForm.endCreateTime = val ? val[1] : null
    }
  },
  methods: {
    /** 修改按钮操作 */
    handleEditTable(row) {
      this.$tab.openPage("修改[" + row.tableName + "]生成配置", '/tool/gen-edit/index/' + row.id);
    },
  }
}
</script>
